import java.util.Collection;
import java.util.Deque;
import java.util.Iterator;


public class BackTrack {
	
	private int top=0;
	private int size;
	
	private int feld[];
	
	public BackTrack(int size){
    
		this.size=size;
	feld=new int[size];
		
	}
	
	public void push(int weg){
		
		int y=weg%10;
		switch(y){
		case 1: y=3;break;
		case 2: break;
		case 3: y=1;
		}
		
		int x=weg/10;
		
		switch(x){
		case 1: x=3;break;
		case 2: break;
		case 3: x=1;
		}
		
		int backtrack=(x*10)+y;
		
		if(top==size)
			top=0;
		feld[top++]=backtrack;
	}
	
	public int  pop(){
	
		if(top==0){
			top=size;
		}
		return feld[--top];
	}
	
	
	
	
	
}
